package config

import (
	"time"
)

// Config 总体配置结构
type Config struct {
	Server    ServerConfig    `yaml:"server"`
	SSL       SSLConfig       `yaml:"ssl"`
	Log       LogConfig       `yaml:"log"`
	Cache     CacheConfig     `yaml:"cache"`
	Proxy     ProxyConfig     `yaml:"proxy"`
	RateLimit RateLimitConfig `yaml:"rate_limit"`
	Plugins   PluginsConfig   `yaml:"plugins"`
	API       APIConfig       `yaml:"api"`
	Backends  []Backend       `yaml:"backends"`
	Health    HealthConfig    `yaml:"health"`
}

type HealthConfig struct {
	Interval time.Duration `yaml:"interval"`
	Timeout  time.Duration `yaml:"timeout"`
	Path     string        `yaml:"path"`
}

type APIConfig struct {
	Enabled    bool   `yaml:"enabled"`
	ListenAddr string `yaml:"listen_addr"`
	Port       int    `yaml:"port"`
}

type Backend struct {
	URL     string `yaml:"url"`
	Weight  int    `yaml:"weight"`
	Healthy bool   `yaml:"healthy"`
}

type ServerConfig struct {
	Host           string        `yaml:"host"`
	Port           int           `yaml:"port"`
	ReadTimeout    time.Duration `yaml:"read_timeout"`
	WriteTimeout   time.Duration `yaml:"write_timeout"`
	MaxHeaderBytes int           `yaml:"max_header_bytes"`
}

type SSLConfig struct {
	Enabled    bool   `yaml:"enabled"`
	CertFile   string `yaml:"cert_file"`
	KeyFile    string `yaml:"key_file"`
	AutoCert   bool   `yaml:"auto_cert"`
	DomainName string `yaml:"domain_name"`
}

type LogConfig struct {
	Level      string `yaml:"level"`
	File       string `yaml:"file"`
	MaxSize    int    `yaml:"max_size"`
	MaxBackups int    `yaml:"max_backups"`
	MaxAge     int    `yaml:"max_age"`
	Compress   bool   `yaml:"compress"`
}

type CacheConfig struct {
	Enabled  bool          `yaml:"enabled"`
	Size     int           `yaml:"size"`
	TTL      time.Duration `yaml:"ttl"`
	Strategy string        `yaml:"strategy"`
}

type ProxyConfig struct {
	Strategy string   `yaml:"strategy"`
	Backends []string `yaml:"backends"`
}

type RateLimitConfig struct {
	Enabled bool    `yaml:"enabled"`
	Rate    float64 `yaml:"rate"`
	Burst   int     `yaml:"burst"`
}

type PluginsConfig struct {
	Directory string   `yaml:"directory"`
	Enabled   []string `yaml:"enabled"`
}
